//初始化病历详情对话框
var CaseAddInfoDlg = {
    caseAddInfoData: {},
    zTreeInstance: null,
    validateFields: {}
};
//清除数据
CaseAddInfoDlg.clearData = function () {
    this.caseAddInfoData = {};
};
//设置对话框中的数据 @param key 数据的名称 @param val 数据的具体值
CaseAddInfoDlg.set = function (key, val) {
    this.caseAddInfoData[key] = (typeof value == "undefined") ? $("#" + key).val() : value;
    return this;
};

CaseAddInfoDlg.get = function (key) {
    return $("#" + key).val();
};

CaseAddInfoDlg.close = function () {
    parent.layer.close(parent.layer.getFrameIndex(window.name));
};

CaseAddInfoDlg.collectData = function () {//收集数据
    this.set('id').set('personacct').set('szm').set('phone').set('nationality').set('nation').set('customerName').set('customerPhone').set('idCard').set('customerAge').set('birthday').set('insuranceState').set('saveStatus').set('selectionStatus').set('customerSex').set('medicalInsurance').set('applyOutpatient')
        .set('occupation').set('flag').set('createTime').set('updateTime').set('applyTime').set('address').set('personCondition').set('maritalStatus').set('medicalDepartment').set('medicalType').set('person_weight').set('personHeight').set('patientComplaints').set('presentIllness')
        .set('pastHistory').set('systemicDiseases').set('diagnosis').set('physicalExam').set('num')
        .set('treatmentAdvice').set('designThink').set('description').set('remarks').set('mark').set('treatmentSteps').set('personWeight')
        .set('code').set('caseType').set('hospitalizedTime').set('BMI').set('suppleExamResult').set('caseComment');
    //治疗步骤
    var treatmentSteps = [];
    $(".treatmentSteps").each(function () {
        treatmentSteps.push($(this).val()); //这里的value就是每一个input的value值~
    });
    this.caseAddInfoData['treatmentSteps'] = treatmentSteps.join("&&");//把一组检查的所有左上数组通过&&分割拼接成字符串 比如  1&&1
    var ratingItemsScoreList = [];
    $(".ratingItemsScore").each(function () {
        ratingItemsScoreList.push($(this).val()); //这里的value就是每一个input的value值~
    });
    this.caseAddInfoData['ratingItemsScore'] = ratingItemsScoreList.join("&&");//把一组检查的所有左上数组通过&&分割拼接成字符串 比如  1&&1
    var ratingItemsList = [];
    $(".ratingItems").each(function () {
        ratingItemsList.push($(this).val()); //这里的value就是每一个input的value值~
    });
    this.caseAddInfoData['ratingItems'] = ratingItemsList.join("&&");//把一组检查的所有左上数组通过&&分割拼接成字符串 比如  1&&1
};

CaseAddInfoDlg.validate = function () {//验证数据是否为空
    $('#caseAddInfoForm').data("bootstrapValidator").resetForm();
    $('#caseAddInfoForm').bootstrapValidator('validate');
    return $("#caseAddInfoForm").data('bootstrapValidator').isValid();
};

CaseAddInfoDlg.storage = function (obj) {//添加暂存病例
    this.clearData();
    this.collectData();
    var ajax = new $ax(Feng.ctxPath + "/caseSelectionUpload/storage", function (data) {
        Feng.success("添加成功!");
        window.parent.CaseSelectionUpload.search();
        CaseAddInfoDlg.close();
    }, function (data) {
        Feng.error("添加失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.caseAddInfoData);
    ajax.start();
};

CaseAddInfoDlg.getCaseQRCode = function (obj) {
    var id = document.getElementById("id").value;
    $.ajax({
        type: "POST",
        url: Feng.ctxPath + "/caseSelectionUpload/getCaseQRCode",
        data: {id: id},
        dataType: "json",
        success: function (data) {
            var index = layer.open({
                type: 2,
                title: '病例评分二维码',
                area: ['40%', '50%'], //宽高
                fix: true, //不固定
                maxmin: true,
                content: Feng.ctxPath + '/caseSelectionVote/to_caseQRCode',
            });
            this.layerIndex = index;
        }
    });
};

CaseAddInfoDlg.selectionstorage = function (obj) {//添加暂存病例
    this.clearData();
    this.collectData();
    var ajax = new $ax(Feng.ctxPath + "/caseSelection/selectionstorage", function (data) {
        Feng.success("添加成功!");
        window.parent.CaseSelection.search();
        CaseAddInfoDlg.close();
    }, function (data) {
        Feng.error("添加失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.caseAddInfoData);
    ajax.start();
};

CaseAddInfoDlg.selectionsubmitTo = function (obj) {//添加暂存病例
    if (confirm("确定提交之后评分不能修改")) {
        this.clearData();
        this.collectData();
        var ajax = new $ax(Feng.ctxPath + "/caseSelection/selectionsubmitTo", function (data) {
            Feng.success("添加成功!");
            window.parent.CaseSelection.search();
            CaseAddInfoDlg.close();
        }, function (data) {
            Feng.error("添加失败!" + data.responseJSON.message + "!");
        });
        ajax.set(this.caseAddInfoData);
        ajax.start();
    }
};

CaseAddInfoDlg.goback = function (obj) {
    var id = document.getElementById("id").value;
    var index = layer.open({
        type: 2,
        title: '病例评分',
        area: ['40%', '50%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/caseSelection/to_goback/' + id
    });
    this.layerIndex = index;
};

CaseAddInfoDlg.submitTo = function (obj) {//添加提交病例
    this.clearData();
    this.collectData();
    var customerName = $("#customerName").val();
    if (customerName == null || customerName == "") {
        layer.alert("请输入患者姓名！");
        return false;
    }
    var customerAge = $("#customerAge").val();
    if (customerAge == null || customerAge == "") {
        layer.alert("请输入年龄！");
        return false;
    }
    var customerSex = $("#customerSex").val();
    if (customerSex == null || customerSex == "") {
        layer.alert("请输入性别！");
        return false;
    }
    var medicalDepartment = $("#medicalDepartment").val();
    if (medicalDepartment == null || medicalDepartment == "") {
        layer.alert("请输入就诊科室！");
        return false;
    }
    var patientComplaints = $("#patientComplaints").val();
    if (patientComplaints == null || patientComplaints == "") {
        layer.alert("请输入患者主诉！");
        return false;
    }
    var presentIllness = $("#presentIllness").val();
    if (presentIllness == null || presentIllness == "") {
        layer.alert("请输入现病史！");
        return false;
    }
    var pastHistory = $("#pastHistory").val();
    if (pastHistory == null || pastHistory == "") {
        layer.alert("请输入既往史！");
        return false;
    }
    var systemicDiseases = $("#systemicDiseases").val();
    if (systemicDiseases == null || systemicDiseases == "") {
        layer.alert("请输入系统疾病史！");
        return false;
    }
    var diagnosis = $("#diagnosis").val();
    if (diagnosis == null || diagnosis == "") {
        layer.alert("请输入诊断！");
        return false;
    }
    var suppleExamResult = $("#suppleExamResult").val();
    if (suppleExamResult == null || suppleExamResult == "") {
        layer.alert("请输入辅助检查结果！");
        return false;
    }
    var hospitalizedTime = $("#hospitalizedTime").val();
    if (hospitalizedTime == null || hospitalizedTime == "") {
        layer.alert("请输入入院时间！");
        return false;
    }
    var avatar4PreId = $("#avatar4PreId").html();
    if (avatar4PreId.trim() == null || avatar4PreId.trim() == "") {
        layer.alert("请输入口内照术前！");
        return false;
    }
    var avatar9PreId = $("#avatar9PreId").html();
    if (avatar9PreId.trim() == null || avatar9PreId.trim() == "") {
        layer.alert("请输入口内照术中！");
        return false;
    }
    var avatar8PreId = $("#avatar8PreId").html();
    if (avatar8PreId.trim() == null || avatar8PreId.trim() == "") {
        layer.alert("请输入口内照术后！");
        return false;
    }
    if (confirm("确定提交之后不能修改和删除病例")) {
        var ajax = new $ax(Feng.ctxPath + "/caseSelectionUpload/submitTo", function (data) {
            if (data == 10001) {
                Feng.success("提交成功!");
                window.parent.CaseSelectionUpload.search();
                CaseAddInfoDlg.close()
            } else {
                alert("每个参赛者最多投递" + data + "份参选病例，您已达到最大投递限额，如有需要请联系举办方！");
                return;
            }
        }, function (data) {
            Feng.error("提交失败!" + data.responseJSON.message + "!");
        });
        ajax.set(this.caseAddInfoData);
        ajax.start();
    }
};

CaseAddInfoDlg.updateStorage = function (obj) {//暂存修改病例
    this.clearData();
    this.collectData();
    var ajax = new $ax(Feng.ctxPath + "/caseSelectionUpload/updatestorage", function (data) {
        Feng.success("修改成功!");
        window.parent.CaseSelectionUpload.search();
        CaseAddInfoDlg.close()
    }, function (data) {
        Feng.error("修改失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.caseAddInfoData);
    ajax.start();
};

CaseAddInfoDlg.updateSubmitTo = function (obj) {
    this.clearData();
    this.collectData();
    var customerName = $("#customerName").val();
    if (customerName == null || customerName == "") {
        layer.alert("请输入患者姓名！");
        return false;
    }
    var customerAge = $("#customerAge").val();
    if (customerAge == null || customerAge == "") {
        layer.alert("请输入年龄！");
        return false;
    }
    var customerSex = $("#customerSex").val();
    if (customerSex == null || customerSex == "") {
        layer.alert("请输入性别！");
        return false;
    }
    var patientComplaints = $("#patientComplaints").val();
    if (patientComplaints == null || patientComplaints == "") {
        layer.alert("请输入患者主诉！");
        return false;
    }
    var presentIllness = $("#presentIllness").val();
    if (presentIllness == null || presentIllness == "") {
        layer.alert("请输入现病史！");
        return false;
    }
    var pastHistory = $("#pastHistory").val();
    if (pastHistory == null || pastHistory == "") {
        layer.alert("请输入既往史！");
        return false;
    }
    var systemicDiseases = $("#systemicDiseases").val();
    if (systemicDiseases == null || systemicDiseases == "") {
        layer.alert("请输入系统疾病史！");
        return false;
    }
    var diagnosis = $("#diagnosis").val();
    if (diagnosis == null || diagnosis == "") {
        layer.alert("请输入诊断！");
        return false;
    }
    var suppleExamResult = $("#suppleExamResult").val();
    if (suppleExamResult == null || suppleExamResult == "") {
        layer.alert("请输入辅助检查结果！");
        return false;
    }
    var hospitalizedTime = $("#hospitalizedTime").val();
    if (hospitalizedTime == null || hospitalizedTime == "") {
        layer.alert("请输入入院时间！");
        return false;
    }
    var avatar4PreId = $("#avatar4PreId").html();
    if (avatar4PreId.trim() == null || avatar4PreId.trim() == "") {
        layer.alert("请输入口内照术前！");
        return false;
    }
    var avatar9PreId = $("#avatar9PreId").html();
    if (avatar9PreId.trim() == null || avatar9PreId.trim() == "") {
        layer.alert("请输入口内照术中！");
        return false;
    }
    var avatar8PreId = $("#avatar8PreId").html();
    if (avatar8PreId.trim() == null || avatar8PreId.trim() == "") {
        layer.alert("请输入口内照术后！");
        return false;
    }
    if (confirm("确定提交之后病例不能修改")) {
        var ajax = new $ax(Feng.ctxPath + "/caseSelectionUpload/updateSubmitTo", function (data) {
            if (data == 10001) {
                Feng.success("提交成功!");
                window.parent.CaseSelectionUpload.search();
                CaseAddInfoDlg.close();
            } else {
                alert("每个参赛者最多投递" + data + "份参选病例，您已达到最大投递限额，如有需要请联系举办方！");
                return;
            }
        }, function (data) {
            Feng.error("提交失败!" + data.responseJSON.message + "!");
        });
        ajax.set(this.caseAddInfoData);
        ajax.start();
    }
};

CaseAddInfoDlg.patient = function () {//微信返回
    if ($("#numValue").val() == '1') {
        window.location.href = Feng.ctxPath + "/weixin/index";
    } else if ($("#numValue").val() == '2') {
        window.location.href = Feng.ctxPath + "/reservation/market_patient";
    }
};

CaseAddInfoDlg.caseScore = function () {//病例评分
    var id = document.getElementById("id").value;
    var index = layer.open({
        type: 2,
        title: '病例评分',
        area: ['40%', '50%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/caseSelectionUpload/doctor_caseScore/' + id
    });
    this.layerIndex = index;
};

CaseAddInfoDlg.caseMarking = function () {//病例标签
    var index = layer.open({
        type: 2,
        title: '病例标签',
        area: ['40%', '50%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/caseSelectionUpload/doctor_caseMarking'
    });
    this.layerIndex = index;
};

CaseAddInfoDlg.initData = function () {//初始化数据
    var seletecustomerSex = $('#customerSexValue').val();
    var seletemaritalStatus = $('#maritalStatusValue').val();
    var seletenationality = $('#nationalityValue').val();
    var seletenation = $('#nationValue').val();
    var seleteinsuranceState = $('#insuranceStateValue').val();
    var seletemedicalType = $('#medicalTypeValue').val();
    if (seletecustomerSex != "") {
        $("#customerSex option[value='" + seletecustomerSex + "']").attr("selected", "selected");
    }
    if (seletemaritalStatus != "") {
        $("#maritalStatus option[value='" + seletemaritalStatus + "']").attr("selected", "selected");
    }
    if (seletenationality != "") {
        $("#nationality option[value='" + seletenationality + "']").attr("selected", "selected");
    }
    if (seletenation != "") {
        $("#nation option[value='" + seletenation + "']").attr("selected", "selected");
    }
    if (seleteinsuranceState != "") {
        $("#insuranceState option[value='" + seleteinsuranceState + "']").attr("selected", "selected");
    }
    if (seletemedicalType != "") {
        $("#medicalType option[value='" + seletemedicalType + "']").attr("selected", "selected");
    }
};

function checkDate() {
    var date = new Date();
    date.setDate(date.getDate() - 1);
    var now = date.valueOf();
    var time = new Date($("#appointmentArrivalTime").val()).valueOf();
    if (now < time) {
        layer.alert("请检查入院时间！");
    }
};

var avatarUp, avatarUp1, avatarUp2, avatarUp3, avatarUp4, avatarUp5, avatarUp6, avatarUp7, avatarUp8, avatarUp9 = "";

function iconTypeChange() {
    avatarUp = new $IconUpload("avatar");
    avatarUp.initIcon();
    avatarUp1 = new $IconUpload("avatar1");
    avatarUp1.initIcon();
    avatarUp2 = new $IconUpload("avatar2");
    avatarUp2.initIcon();
    avatarUp3 = new $IconUpload("avatar3");
    avatarUp3.initIcon();
    avatarUp4 = new $IconUpload("avatar4");
    avatarUp4.initIcon();
    avatarUp5 = new $IconUpload("avatar5");
    avatarUp5.initIcon();
    avatarUp6 = new $IconUpload("avatar6");
    avatarUp6.initIcon();
    avatarUp7 = new $IconUpload("avatar7");
    avatarUp7.initIcon();
    avatarUp8 = new $IconUpload("avatar8");
    avatarUp8.initIcon();
    avatarUp9 = new $IconUpload("avatar9");
    avatarUp9.initIcon();
}

$(".add").click(function () {
    var mode = $(this).parent().children().eq(1).clone();
    $(mode).find('.treatmentSteps').val("");
    $(this).before(mode);
});

$(".consulFormation").on('click', '.deleteBtn', function () {
    var index = $(this).parents('.treatmentStepsContent').index();
    if (index != 1) {
        $(this).parents('.treatmentStepsContent').remove()
    }
});

$(function () {
    Feng.initValidator("caseAddInfoForm", CaseAddInfoDlg.validateFields);
    CaseAddInfoDlg.initData();
    iconTypeChange();

    $(".modify").attr("readOnly", "true");
    $(".select_styles").attr("disabled", "disabled");

    $("#customerAge").on('input', function () {//输入年龄出生日期显示
        var date = new Date();
        var currentYear = date.getFullYear() - $("#customerAge").val();
        $("#birthday").val(currentYear + "-01-01");
    });

    $("#birthday").on("input", function () {
        var resbirthday = /^(19\d\d|20\d\d)[-/ ](0\d|1[0-2])[-/ ](0\d|[1-2]\d|30|31)$/;
        var birthday = $("#birthday").val();
        if (birthday.length > 0 && birthday.length < 4) {
        } else if (birthday.length >= 4 && birthday.length < 10) {
            var s = birthday.substring(0, 4);
            if (!isNaN(s)) {
                var data = new Date();
                $("#customerAge").val(data.getFullYear() - s);
            }
        } else {
            if (resbirthday.test(birthday)) {
                var birthDayTime = new Date(birthday).getTime();
                var nowTime = new Date().getTime();
                $("#customerAge").val(Math.ceil((nowTime - birthDayTime) / 31536000000));
            } else {
                Feng.error("请输入正确的格式！");
            }
        }
    });

    $(document).on('click', '.cp_img_delete', function () {
        var that = this;
        var id = $(that).parent().attr("id");
        var customerId = $("id").val();
        $.ajax({
            url: Feng.ctxPath + "/caseSelectionUpload/delteProcess",
            type: "post",
            data: {"id": id, "customerId": customerId},
            success: function (data) {
                $(that).parent().hide();
                Feng.success("删除成功！");
            },
            error: function (data) {
                alert("删除失败！");
            }
        })
    });

    var tips;
    var toothId;
    $("#projectListInfo").on('click', '.toothBox', function (e) {
        e.stopPropagation();
        $(".toothBox").removeClass('tips');
        $(this).addClass('tips');
        toothId = $(this).attr("id");
        var leftUpNum = $(this).find('.leftUp').text();
        var rightUpNum = $(this).find('.rightUp').text();
        var leftDownNum = $(this).find('.leftDown').text();
        var rightDownNum = $(this).find('.rightDown').text();
        tips = layer.open({
            type: 4,
            tips: [1, '#ffffff'],
            closeBtn: 0,
            area: ['auto', 'auto'],
            content: ['<div>' + $("#noneBox").html() + '</div>', '.tips'],
            success: function (layero, index) {
                if (leftUpNum.length > 0) {
                    for (var w = 0; w < $(layero).find('.toothTopLeft>span').length; w++) {
                        for (var i = 0; i < leftUpNum.length; i++) {
                            if ($(layero).find('.toothTopLeft>span').eq(w).find('span').text() == leftUpNum.substring(i, i + 1)) {
                                $(layero).find('.toothTopLeft>span').eq(w).find('span').addClass('spanStyle');
                            }
                        }
                    }
                }
                if (rightUpNum.length > 0) {
                    for (var w = 0; w < $(layero).find('.toothTopRight>span').length; w++) {
                        for (var i = 0; i < rightUpNum.length; i++) {
                            if ($(layero).find('.toothTopRight>span').eq(w).find('span').text() == rightUpNum.substring(i, i + 1)) {
                                $(layero).find('.toothTopRight>span').eq(w).find('span').addClass('spanStyle');
                            }
                        }
                    }
                }
                if (leftDownNum.length > 0) {
                    for (var w = 0; w < $(layero).find('.toothBottomLeft>span').length; w++) {
                        for (var i = 0; i < leftDownNum.length; i++) {
                            if ($(layero).find('.toothBottomLeft>span').eq(w).find('span').text() == leftDownNum.substring(i, i + 1)) {
                                $(layero).find('.toothBottomLeft>span').eq(w).find('span').addClass('spanStyle');
                            }
                        }
                    }
                }
                if (rightDownNum.length > 0) {
                    for (var w = 0; w < $(layero).find('.toothBottomRight>span').length; w++) {
                        for (var i = 0; i < rightDownNum.length; i++) {
                            if ($(layero).find('.toothBottomRight>span').eq(w).find('span').text() == rightDownNum.substring(i, i + 1)) {
                                $(layero).find('.toothBottomRight>span').eq(w).find('span').addClass('spanStyle');
                            }
                        }
                    }
                }
            }
        });
    });

    $(document).click(function () {
        layer.close(tips);
    });

    $(document).on('click', '.tipsUl>li', function (e) {
        e.stopPropagation();
        $(this).addClass('tipsLi').siblings().removeClass('tipsLi');
        if ($(this).index() == 0) {
            $(this).parent().siblings().children('#permanent').show().siblings().hide()
        } else if ($(this).index() == 1) {
            $(this).parent().siblings().children('#deciduous').show().siblings().hide()
        }
    });

    $(document).on('click', '.toothTopLeft>span', function (e) {
        e.stopPropagation();
        var arr = [];
        var text = $(this).text();
        if ($(this).children().hasClass('spanStyle')) {
            var inputValue = $(".tips .leftUp").text().replace(text, "");
            for (var i = 0; i < inputValue.length; i++) {
                arr.push(inputValue.substring(i, i + 1));
            }
            for (var i = arr.length - 1; i >= 0; i--) {
                for (var j = 0; j < i; j++) {
                    if (arr[j + 1] > arr[j]) {
                        var change = arr[j + 1];
                        arr[j + 1] = arr[j];
                        arr[j] = change;
                    }
                }
            }
            var str = "";
            for (var i = 0; i < arr.length; i++) {
                str += arr[i];
            }
            $(".tips .leftUp").text(str);
            $(this).children().removeClass('spanStyle');
        } else {
            $(this).children().addClass('spanStyle');
            var add = $(".tips .leftUp").text() + text;
            for (var d = 0; d < add.length; d++) {
                arr.push(add.substring(d, d + 1));
            }
            for (var i = arr.length - 1; i >= 0; i--) {
                for (var j = 0; j < i; j++) {
                    if (arr[j + 1] > arr[j]) {
                        var change = arr[j + 1];
                        arr[j + 1] = arr[j];
                        arr[j] = change;
                    }
                }
            }
            var str = "";
            for (var i = 0; i < arr.length; i++) {
                str += arr[i];
            }
            $(".tips .leftUp").text(str);
        }
    });

    $(document).on('click', '.toothTopRight>span', function (e) {
        e.stopPropagation();
        var arr = [];
        var text = $(this).text();
        if ($(this).children().hasClass('spanStyle')) {
            var inputValue = $(".tips .rightUp").text().replace(text, "");
            for (var i = 0; i < inputValue.length; i++) {
                arr.push(inputValue.substring(i, i + 1));
            }
            for (var i = arr.length - 1; i >= 0; i--) {
                for (var j = 0; j < i; j++) {
                    if (arr[j + 1] < arr[j]) {
                        var change = arr[j + 1];
                        arr[j + 1] = arr[j];
                        arr[j] = change
                    }
                }
            }
            var str = "";
            for (var i = 0; i < arr.length; i++) {
                str += arr[i];
            }
            $(".tips .rightUp").text(str);
            $(this).children().removeClass('spanStyle');
        } else {
            $(this).children().addClass('spanStyle');
            var add = $(".tips .rightUp").text() + text;
            for (var d = 0; d < add.length; d++) {
                arr.push(add.substring(d, d + 1));
            }
            for (var i = arr.length - 1; i >= 0; i--) {
                for (var j = 0; j < i; j++) {
                    if (arr[j + 1] < arr[j]) {
                        var change = arr[j + 1];
                        arr[j + 1] = arr[j];
                        arr[j] = change;
                    }
                }
            }
            var str = "";
            for (var i = 0; i < arr.length; i++) {
                str += arr[i]
            }
            $(".tips .rightUp").text(str);
        }
    });

    $(document).on('click', '.toothBottomLeft>span', function (e) {
        e.stopPropagation();
        var arr = [];
        var text = $(this).text();
        if ($(this).children().hasClass('spanStyle')) {
            var inputValue = $(".tips .leftDown").text().replace(text, "");
            for (var i = 0; i < inputValue.length; i++) {
                arr.push(inputValue.substring(i, i + 1));
            }
            for (var i = arr.length - 1; i >= 0; i--) {
                for (var j = 0; j < i; j++) {
                    if (arr[j + 1] > arr[j]) {
                        var change = arr[j + 1];
                        arr[j + 1] = arr[j];
                        arr[j] = change
                    }
                }
            }
            var str = "";
            for (var i = 0; i < arr.length; i++) {
                str += arr[i]
            }
            $(".tips .leftDown").text(str);
            $(this).children().removeClass('spanStyle');
        } else {
            $(this).children().addClass('spanStyle');
            var add = $(".tips .leftDown").text() + text;
            for (var d = 0; d < add.length; d++) {
                arr.push(add.substring(d, d + 1));
            }
            for (var i = arr.length - 1; i >= 0; i--) {
                for (var j = 0; j < i; j++) {
                    if (arr[j + 1] > arr[j]) {
                        var change = arr[j + 1];
                        arr[j + 1] = arr[j];
                        arr[j] = change;
                    }
                }
            }
            var str = "";
            for (var i = 0; i < arr.length; i++) {
                str += arr[i];
            }
            $(".tips .leftDown").text(str);
        }
    });

    $(document).on('click', '.toothBottomRight>span', function (e) {
        e.stopPropagation();
        var arr = [];
        var text = $(this).text();
        if ($(this).children().hasClass('spanStyle')) {
            var inputValue = $(".tips .rightDown").text().replace(text, "");
            for (var i = 0; i < inputValue.length; i++) {
                arr.push(inputValue.substring(i, i + 1));
            }
            for (var i = arr.length - 1; i >= 0; i--) {
                for (var j = 0; j < i; j++) {
                    if (arr[j + 1] < arr[j]) {
                        var change = arr[j + 1];
                        arr[j + 1] = arr[j];
                        arr[j] = change;
                    }
                }
            }
            var str = "";
            for (var i = 0; i < arr.length; i++) {
                str += arr[i];
            }
            $(".tips .rightDown").text(str);
            $(this).children().removeClass('spanStyle');
        } else {
            $(this).children().addClass('spanStyle');
            var add = $(".tips .rightDown").text() + text;
            for (var d = 0; d < add.length; d++) {
                arr.push(add.substring(d, d + 1));
            }
            for (var i = arr.length - 1; i >= 0; i--) {
                for (var j = 0; j < i; j++) {
                    if (arr[j + 1] < arr[j]) {
                        var change = arr[j + 1];
                        arr[j + 1] = arr[j];
                        arr[j] = change;
                    }
                }
            }
            var str = "";
            for (var i = 0; i < arr.length; i++) {
                str += arr[i];
            }
            $(".tips .rightDown").text(str);
        }
    });
});